import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEMainState } from './ipsdemain-state';
import { IPSDEMainStateRS } from './ipsdemain-state-rs';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEMainStateRSImpl extends PSModelObjectImpl implements IPSDEMainStateRS, IPSModelSortable {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected nextpsdemainstate: IPSDEMainState | null = null;

  getNextPSDEMainState(): IPSDEMainState | null {
    if (this.nextpsdemainstate != null) return this.nextpsdemainstate;
    const value = this.M.getNextPSDEMainState;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.nextpsdemainstate = ipsdataentity.findPSDEMainState(value);
    }
    return this.nextpsdemainstate;
  }

  get nextPSDEMainState(): IPSDEMainState | null {
    return this.getNextPSDEMainState();
  }

  getNextPSDEMainStateMust(): IPSDEMainState {
    const value = this.getNextPSDEMainState();
    if (value == null) {
      throw new Error('未指定进入主状态');
    }
    return value;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected prevpsdemainstate: IPSDEMainState | null = null;

  getPrevPSDEMainState(): IPSDEMainState | null {
    if (this.prevpsdemainstate != null) return this.prevpsdemainstate;
    const value = this.M.getPrevPSDEMainState;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.prevpsdemainstate = ipsdataentity.findPSDEMainState(value);
    }
    return this.prevpsdemainstate;
  }

  get prevPSDEMainState(): IPSDEMainState | null {
    return this.getPrevPSDEMainState();
  }

  getPrevPSDEMainStateMust(): IPSDEMainState {
    const value = this.getPrevPSDEMainState();
    if (value == null) {
      throw new Error('未指定前序主状态');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDEMainStateRSImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.mainstate.IPSDEMainStateRS') return true;
    return super.instanceof(cls);
  }
}
